#include <iostream>
#include "Solution.h"

int main()
{
	vector<Interval> intervals;
	int m;
	cin>>m;
	for(int i=0;i<m;i++)
	{
		Interval inter;
		cin>>inter.start>>inter.end;
		intervals.push_back(inter);
	}

	vector<Interval> result = Solution().merge(intervals);

	for(size_t i=0;i<result.size();i++)
	{
		cout<<result[i].start<<" "<<result[i].end<<endl;
	}
	
	while(cin.get() != '\n');
	cin.get();
}